package com.xintonghua.bussiness.ui.fragment.cube.turnover;

import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.SeekBar;
import android.widget.TextView;

import com.github.mikephil.charting.animation.Easing;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieData;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.formatter.PercentFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.xintonghua.bussiness.R;
import com.xintonghua.bussiness.base.BaseActivity;
import com.xintonghua.bussiness.bean.CubeBean;
import com.xintonghua.bussiness.bean.TaskBean;
import com.xintonghua.bussiness.bean.TaskBeans;
import com.xintonghua.bussiness.bean.TongJiBean;
import com.xintonghua.bussiness.ui.fragment.cube.turnover.tongji.DayAxisValueFormatter;
import com.xintonghua.bussiness.ui.fragment.cube.turnover.tongji.MyAxisValueFormatter;
import com.xintonghua.bussiness.ui.fragment.cube.turnover.tongji.XYMarkerView;
import com.xintonghua.bussiness.util.AbstractBaseAdapter;
import com.xintonghua.bussiness.util.JsonUtil;
import com.xintonghua.bussiness.util.JumpUtils;
import com.xintonghua.bussiness.util.MathUtils;
import com.xintonghua.bussiness.util.MyState;
import com.xintonghua.bussiness.util.MyUtils;
import com.xintonghua.bussiness.util.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 营业额
 */
public class TurnoverActivity extends BaseActivity implements SeekBar.OnSeekBarChangeListener,
        OnChartValueSelectedListener, initTongjiTu {

    @BindView(R.id.bar_chat)
    BarChart barChat;
    @BindView(R.id.sag_graidview)
    GridView sagGraidview;
    @BindView(R.id.sag_graidview2)
    GridView sagGraidview2;

    @BindView(R.id.pc_chart)
    PieChart pcChart;

    CubeBean bean;

    String type;
    @BindView(R.id.tv_xiangmuming)
    TextView tvXiangmuming;
    @BindView(R.id.tv_xiangmuming2)
    TextView tvXiangmuming2;

    String starttime = null;
    String endtime = null;

    //必传项 ：type    CubeBean的id    标题显示要CubeBean的Name
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_turnover);
        ButterKnife.bind(this);
        onSimpleActionBar();
        starttime = JumpUtils.getString(this, "starttime");
        endtime = JumpUtils.getString(this, "endtime");

        bean = (CubeBean) JumpUtils.getSerializable(this);
        setSimpleActionBar("" + bean.getName());
        tvXiangmuming.setText("" + bean.getName() + "项目");
        tvXiangmuming2.setText("" + bean.getName() + "项目");
        type = JumpUtils.getString(this, "type");
        initTongjituOption2();
        setData0();
//        initShanXingTuNull();
        getNetData();

    }

    public void initTongjituOption() {
        barChat.getDescription().setEnabled(false);
        // if more than 60 entries are displayed in the chart, no values will be
        // drawn
        barChat.setMaxVisibleValueCount(60);

        // scaling can now only be done on x- and y-axis separately
        barChat.setPinchZoom(false);

        barChat.setDrawBarShadow(false);
        barChat.setDrawGridBackground(false);

        XAxis xAxis = barChat.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setDrawGridLines(false);

        barChat.getAxisLeft().setDrawGridLines(false);

        // setting data
//        mSeekBarX.setProgress(10);
//        mSeekBarY.setProgress(100);

        // add a nice and smooth animation
        barChat.animateY(2500);

        barChat.getLegend().setEnabled(false);
        barChat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MyUtils.mToast(TurnoverActivity.this, "那你点击了");
            }
        });

    }

    public void initTongjituData() {
        ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
        for (int i = 0; i < 4 + 1; i++) {
            float mult = (i + 1);
            float val = 100 * mult;//(float) (Math.random() * mult) + mult / 3;
            yVals1.add(new BarEntry(i, val));
        }
        BarDataSet set1;
        if (barChat.getData() != null &&
                barChat.getData().getDataSetCount() > 0) {
            set1 = (BarDataSet) barChat.getData().getDataSetByIndex(0);
            set1.setValues(yVals1);
            barChat.getData().notifyDataChanged();
            barChat.notifyDataSetChanged();
        } else {
            set1 = new BarDataSet(yVals1, "Data Set");
            set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
            set1.setDrawValues(false);

            ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
            dataSets.add(set1);

            BarData data = new BarData(dataSets);
            barChat.setData(data);
            barChat.setFitBars(true);
        }

        barChat.invalidate();
    }

    @Override
    public void getNetData() {
            httpCent.getTongJiDetail(bean.getId(), type, starttime, endtime, this, MyState.requestOne);



    }

    TongJiBean tongjibean;

    @Override
    public void dataBack(Object data, int order) {
        super.dataBack(data, order);
        try {
            switch (order) {
                case MyState.requestOne:
                    tongjibean = JsonUtil.getEntityByJsonString(data.toString(), TongJiBean.class);
                    initTongjituOption2();
                    initTongjitu();
                    initGridView();
//                    initTongjituOption2();
                    initShanXingTu();
                    initGridView2();
                    break;

            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.i("aaa", "数据错误");
        }
    }

    @Override
    public void initTongjituOption2() {

        barChat.setOnChartValueSelectedListener(this);

        barChat.setDrawBarShadow(false);
        barChat.setDrawValueAboveBar(true);

        barChat.getDescription().setEnabled(false);

        // if more than 60 entries are displayed in the chart, no values will be
        // drawn
        barChat.setMaxVisibleValueCount(60);

        // scaling can now only be done on x- and y-axis separately
        barChat.setPinchZoom(false);

        barChat.setDrawGridBackground(false);
        // barChat.setDrawYLabels(false);

    }

    @Override
    public void initTongjitu() {

        IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(barChat);

        XAxis xAxis = barChat.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
//        xAxis.setTypeface(mTfLight);设置字体
        xAxis.setDrawGridLines(false);
        xAxis.setGranularity(1f); // only intervals of 1 day
        xAxis.setLabelCount(5);//设置下面表签数量
        xAxis.setValueFormatter(xAxisFormatter);

        IAxisValueFormatter custom = new MyAxisValueFormatter();
//下面的是左边的那部分
        YAxis leftAxis = barChat.getAxisLeft();
        leftAxis.setTypeface(mTfLight);
        leftAxis.setLabelCount(4, false);
        leftAxis.setValueFormatter(custom);
        leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
        leftAxis.setSpaceTop(15f);
        leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
//下面的是右边边的那部分
        YAxis rightAxis = barChat.getAxisRight();
        rightAxis.setDrawGridLines(false);
        rightAxis.setTypeface(mTfLight);
        rightAxis.setLabelCount(4, false);
        rightAxis.setValueFormatter(custom);
        rightAxis.setSpaceTop(15f);
        rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

        Legend l = barChat.getLegend();
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
        l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
        l.setDrawInside(false);
        l.setForm(Legend.LegendForm.SQUARE);
        l.setFormSize(9f);
        l.setTextSize(8f);
        l.setXEntrySpace(4f);
        // l.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
        // "def", "ghj", "ikl", "mno" });
        // l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc",
        // "def", "ghj", "ikl", "mno" });

        XYMarkerView mv = new XYMarkerView(this, xAxisFormatter);
        mv.setChartView(barChat); // For bounds control
        barChat.setMarker(mv); // Set the marker to the chart
        setData(4, 16000);
        // setting data
//        mSeekBarY.setProgress(50);
//        mSeekBarX.setProgress(12);
//
//        mSeekBarY.setOnSeekBarChangeListener(this);
//        mSeekBarX.setOnSeekBarChangeListener(this);
    }

    protected Typeface mTfLight;

    @Override
    public void setData0() {

        float start = 0f;

        ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();

        for (int i = (int) start; i < 5; i++) {

            switch (i) {
                case 0:
                    yVals1.add(new BarEntry(i, 0));
                    break;
                case 1:
                    yVals1.add(new BarEntry(i, 0));
                    break;
                case 2:
                    yVals1.add(new BarEntry(i, 0));
                    break;
                case 3:
                    yVals1.add(new BarEntry(i, 0));
                    break;
                case 4:
                    yVals1.add(new BarEntry(i, 0));
                    break;
            }
//            float mult = (range + 1);
//            float val = (float) (Math.random() * mult);
//
//            if (Math.random() * 100 < 25) {
//                yVals1.add(new BarEntry(i, val));
//            } else {
//                yVals1.add(new BarEntry(i, val));
//            }
        }

        BarDataSet set1;
        set1 = new BarDataSet(yVals1, "金额");
        set1.setColor(Color.parseColor("#ff6285"));
        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(set1);
        BarData data = new BarData(dataSets);
        barChat.setData(data);

//        if (barChat.getData() != null &&
//                barChat.getData().getDataSetCount() > 0) {
//            set1 = (BarDataSet) barChat.getData().getDataSetByIndex(0);
//            set1.setValues(yVals1);
//            barChat.getData().notifyDataChanged();
//            barChat.notifyDataSetChanged();
//        }

//
//        if (barChat.getData() != null &&
//                barChat.getData().getDataSetCount() > 0) {
//            set1 = (BarDataSet) barChat.getData().getDataSetByIndex(0);
//            set1.setValues(yVals1);
//            barChat.getData().notifyDataChanged();
//            barChat.notifyDataSetChanged();
//        } else {
//            set1 = new BarDataSet(yVals1, "The year 2017");
//
//            set1.setDrawIcons(false);
//
//            set1.setColors(ColorTemplate.MATERIAL_COLORS);
//
//            ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
//            dataSets.add(set1);
//
//            BarData data = new BarData(dataSets);
//            data.setValueTextSize(10f);
////            data.setValueTypeface(mTfLight);
//            data.setBarWidth(0.9f);
//
//            barChat.setData(data);
//        }
    }

    @Override
    public void setData(int count, float range) {

        float start = 0f;

        ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();

        for (int i = (int) start; i < 5; i++) {

            switch (i) {
                case 0:
                    yVals1.add(new BarEntry(i, Float.parseFloat(tongjibean.getDown20Money())));
                    break;
                case 1:
                    yVals1.add(new BarEntry(i, Float.parseFloat(tongjibean.getDown30Money())));
                    break;
                case 2:
                    yVals1.add(new BarEntry(i, Float.parseFloat(tongjibean.getDown40Money())));
                    break;
                case 3:
                    yVals1.add(new BarEntry(i, Float.parseFloat(tongjibean.getDown50Money())));
                    break;
                case 4:
                    yVals1.add(new BarEntry(i, Float.parseFloat(tongjibean.getOver50Money())));
                    break;
            }
//            float mult = (range + 1);
//            float val = (float) (Math.random() * mult);
//
//            if (Math.random() * 100 < 25) {
//                yVals1.add(new BarEntry(i, val));
//            } else {
//                yVals1.add(new BarEntry(i, val));
//            }
        }

        BarDataSet set1;
        set1 = new BarDataSet(yVals1, "金额");
        set1.setColor(Color.parseColor("#ff6285"));
        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(set1);
        BarData data = new BarData(dataSets);
        barChat.setData(data);

//        if (barChat.getData() != null &&
//                barChat.getData().getDataSetCount() > 0) {
//            set1 = (BarDataSet) barChat.getData().getDataSetByIndex(0);
//            set1.setValues(yVals1);
//            barChat.getData().notifyDataChanged();
//            barChat.notifyDataSetChanged();
//        }

//
//        if (barChat.getData() != null &&
//                barChat.getData().getDataSetCount() > 0) {
//            set1 = (BarDataSet) barChat.getData().getDataSetByIndex(0);
//            set1.setValues(yVals1);
//            barChat.getData().notifyDataChanged();
//            barChat.notifyDataSetChanged();
//        } else {
//            set1 = new BarDataSet(yVals1, "The year 2017");
//
//            set1.setDrawIcons(false);
//
//            set1.setColors(ColorTemplate.MATERIAL_COLORS);
//
//            ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
//            dataSets.add(set1);
//
//            BarData data = new BarData(dataSets);
//            data.setValueTextSize(10f);
////            data.setValueTypeface(mTfLight);
//            data.setBarWidth(0.9f);
//
//            barChat.setData(data);
//        }
    }

    @Override
    public void initGridView() {

        List<TaskBeans.ProjectListBean> projectListBeans = new ArrayList<>();

        for (int i = 0; i < 18; i++) {
            projectListBeans.add(new TaskBeans.ProjectListBean());
        }
        sagGraidview.setAdapter(new AbstractBaseAdapter<TaskBeans.ProjectListBean>(projectListBeans) {

            @Override
            public View getAdapterViewAtPosition(int position, View convertView, ViewGroup parent) {
                TaskBeans.ProjectListBean bean = getItem(position);
                if (convertView == null) {
                    convertView = LayoutInflater.from(TurnoverActivity.this).inflate(R.layout.item_adapter_turnover, null);
                }
                TextView tv_text = ViewHolder.get(convertView, R.id.tv_text);

                switch (position) {
                    case 0:
                        tv_text.setText("年龄");
                        break;
                    case 1:
                        tv_text.setText("人数");
                        break;
                    case 2:
                        tv_text.setText("消费");
                        break;
                    case 3:
                        tv_text.setText("20岁以下");
                        break;
                    case 4:
                        tv_text.setText("" + tongjibean.getDown20());
                        break;
                    case 5:
                        tv_text.setText("" + tongjibean.getDown20Money());
                        break;
                    case 6:
                        tv_text.setText("20-30岁");
                        break;
                    case 7:
                        tv_text.setText("" + tongjibean.getDown30());
                        break;
                    case 8:
                        tv_text.setText("" + tongjibean.getDown30Money());
                        break;
                    case 9:
                        tv_text.setText("30-40岁");
                        break;
                    case 10:
                        tv_text.setText("" + tongjibean.getDown40());
                        break;
                    case 11:
                        tv_text.setText("" + tongjibean.getDown40Money());
                        break;

                    case 12:
                        tv_text.setText("40-50岁");
                        break;
                    case 13:
                        tv_text.setText("" + tongjibean.getDown50());
                        break;
                    case 14:
                        tv_text.setText("" + tongjibean.getDown50Money());
                        break;
                    case 15:
                        tv_text.setText("50岁以上");
                        break;
                    case 16:
                        tv_text.setText("" + tongjibean.getOver50());
                        break;
                    case 17:
                        tv_text.setText("" + tongjibean.getOver50Money());
                        break;

                }


                return convertView;
            }
        });
    }

    @Override
    public void initShanXingTuNull() {

        pcChart.setUsePercentValues(true);
        pcChart.getDescription().setEnabled(false);
        pcChart.setExtraOffsets(5, 10, 5, 5);

        pcChart.setDragDecelerationFrictionCoef(0.95f);

//        tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

//        pcChart.setCenterTextTypeface(Typeface.createFromAsset(getAssets(), "OpenSans-Light.ttf"));
//        pcChart.setCenterText(generateCenterSpannableText());

        pcChart.setExtraOffsets(20.f, 0.f, 20.f, 0.f);

        pcChart.setDrawHoleEnabled(true);
        pcChart.setHoleColor(Color.WHITE);

        pcChart.setTransparentCircleColor(Color.WHITE);
        pcChart.setTransparentCircleAlpha(110);

        pcChart.setHoleRadius(58f);
        pcChart.setTransparentCircleRadius(61f);

        pcChart.setDrawCenterText(true);

        pcChart.setRotationAngle(0);
        // enable rotation of the chart by touch
        pcChart.setRotationEnabled(true);
        pcChart.setHighlightPerTapEnabled(true);

        // pcChart.setUnit(" €");
        // pcChart.setDrawUnitsInChart(true);

        // add a selection listener
        pcChart.setOnChartValueSelectedListener(this);

        setData2NULL();

        pcChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
        // pcChart.spin(2000, 0, 360);

        Legend l = pcChart.getLegend();
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
        l.setOrientation(Legend.LegendOrientation.VERTICAL);
        l.setDrawInside(false);
        l.setEnabled(false);
    }

    @Override
    public void setData2NULL() {

        float mult = 100;

        ArrayList<PieEntry> entries = new ArrayList<PieEntry>();

        // NOTE: The order of the entries when being added to the entries array determines their position around the center of
        // the chart.
        for (int i = 0; i < 4; i++) {
            entries.add(new PieEntry((float) (Math.random() * mult) + mult / 5, mParties[i % mParties.length]));
        }

        PieDataSet dataSet = new PieDataSet(entries, "Election Results");
        dataSet.setSliceSpace(3f);
        dataSet.setSelectionShift(5f);

        // add a lot of colors

        ArrayList<Integer> colors = new ArrayList<Integer>();

        for (int c : ColorTemplate.VORDIPLOM_COLORS)
            colors.add(c);

        for (int c : ColorTemplate.JOYFUL_COLORS)
            colors.add(c);

        for (int c : ColorTemplate.COLORFUL_COLORS)
            colors.add(c);

        for (int c : ColorTemplate.LIBERTY_COLORS)
            colors.add(c);

        for (int c : ColorTemplate.PASTEL_COLORS)
            colors.add(c);

        colors.add(ColorTemplate.getHoloBlue());

        dataSet.setColors(colors);
        //dataSet.setSelectionShift(0f);

        dataSet.setValueLinePart1OffsetPercentage(80.f);
        dataSet.setValueLinePart1Length(0.2f);
        dataSet.setValueLinePart2Length(0.4f);
        //dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
        dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);

        PieData data = new PieData(dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(11f);
        data.setValueTextColor(Color.BLACK);
//        data.setValueTypeface(tf);
        pcChart.setData(data);

        // undo all highlights
        pcChart.highlightValues(null);

        pcChart.invalidate();
    }


    @Override
    public void onProgressChanged(SeekBar seekBar, int i, boolean b) {

    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onValueSelected(Entry e, Highlight h) {

    }

    @Override
    public void onNothingSelected() {

    }

    protected String[] mParties = new String[]{
            "Party A", "Party B", "Party C", "Party D", "Party E", "Party F", "Party G", "Party H",
            "Party I", "Party J", "Party K", "Party L", "Party M", "Party N", "Party O", "Party P",
            "Party Q", "Party R", "Party S", "Party T", "Party U", "Party V", "Party W", "Party X",
            "Party Y", "Party Z"
    };

    @Override
    public void setData2(int count, float range) {

        float mult = range;

        ArrayList<PieEntry> entries = new ArrayList<PieEntry>();

        // NOTE: The order of the entries when being added to the entries array determines their position around the center of
        // the chart.
        for (int i = 0; i < 2; i++) {

            switch (i) {
                case 0:
                    if (MathUtils.strcompareTo(tongjibean.getManMoney(), "0")) {
                        entries.add(new PieEntry(Float.parseFloat(tongjibean.getManMoney()), tongjibean.getMan() + "人" + tongjibean.getManMoney()));//mParties[i % mParties.length]
                    } else {
                        entries.add(new PieEntry(Float.parseFloat("0.01"), tongjibean.getMan() + "人" + tongjibean.getManMoney()));//mParties[i % mParties.length]
                    }
                    break;
                case 1:
                    if (MathUtils.strcompareTo(tongjibean.getWomanMoney(), "0")) {
                        entries.add(new PieEntry(Float.parseFloat(tongjibean.getWomanMoney()), tongjibean.getWoman() + "人" + tongjibean.getWomanMoney()));//mParties[i % mParties.length]
                    } else {
                        entries.add(new PieEntry(Float.parseFloat("0.01"), tongjibean.getWoman() + "人" + tongjibean.getWomanMoney()));//mParties[i % mParties.length]
                    }

//
//                    entries.add(new PieEntry(Float.parseFloat("1000"), tongjibean.getWoman() + "人" + tongjibean.getWomanMoney()));//mParties[i % mParties.length]
                    break;
            }

        }

        PieDataSet dataSet = new PieDataSet(entries, "Election Results");
        dataSet.setSliceSpace(3f);
        dataSet.setSelectionShift(5f);

        // add a lot of colors

        ArrayList<Integer> colors = new ArrayList<Integer>();

//        for (int c : ColorTemplate.VORDIPLOM_COLORS)
//            colors.add(c);
//
//        for (int c : ColorTemplate.JOYFUL_COLORS)
//            colors.add(c);
//
//        for (int c : ColorTemplate.COLORFUL_COLORS)
//            colors.add(c);
//
//        for (int c : ColorTemplate.LIBERTY_COLORS)
//            colors.add(c);
//
//        for (int c : ColorTemplate.PASTEL_COLORS)
//            colors.add(c);
//
//        colors.add(ColorTemplate.getHoloBlue());
        colors.add(Color.rgb(30, 168, 255));
        colors.add(Color.rgb(255, 75, 109));
        dataSet.setColors(colors);
        //dataSet.setSelectionShift(0f);

        dataSet.setValueLinePart1OffsetPercentage(80.f);
        dataSet.setValueLinePart1Length(0.2f);
        dataSet.setValueLinePart2Length(0.4f);
        //dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
        dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);

        PieData data = new PieData(dataSet);
        data.setValueFormatter(new PercentFormatter());
        data.setValueTextSize(11f);
        data.setValueTextColor(Color.BLACK);
//        data.setValueTypeface(tf);
        pcChart.setData(data);
        pcChart.setRotationEnabled(false);
        // undo all highlights
        pcChart.highlightValues(null);

        pcChart.invalidate();
    }

    @Override
    public void initGridView2() {

        List<TaskBeans.ProjectListBean> projectListBeans = new ArrayList<>();
        for (int i = 0; i < 9; i++) {
            projectListBeans.add(new TaskBeans.ProjectListBean());
        }
        sagGraidview2.setAdapter(new AbstractBaseAdapter<TaskBeans.ProjectListBean>(projectListBeans) {

            @Override
            public View getAdapterViewAtPosition(int position, View convertView, ViewGroup parent) {
                TaskBeans.ProjectListBean bean = getItem(position);
                if (convertView == null) {
                    convertView = LayoutInflater.from(TurnoverActivity.this).inflate(R.layout.item_adapter_turnover, null);
                }
                TextView tv_text = ViewHolder.get(convertView, R.id.tv_text);

                switch (position) {
                    case 0:
                        tv_text.setText("性别");
                        break;
                    case 1:
                        tv_text.setText("人数");
                        break;
                    case 2:
                        tv_text.setText("消费金额");
                        break;
                    case 3:
                        tv_text.setText("男性");
                        break;
                    case 4:
                        tv_text.setText("" + tongjibean.getMan());
                        break;
                    case 5:
                        tv_text.setText("" + tongjibean.getManMoney());
                        break;
                    case 6:
                        tv_text.setText("女性");
                        break;
                    case 7:
                        tv_text.setText("" + tongjibean.getWoman());
                        break;
                    case 8:
                        tv_text.setText("" + tongjibean.getWomanMoney());
                        break;
                }
                return convertView;
            }
        });

    }


    @Override
    public void initShanXingTu() {

        pcChart.setUsePercentValues(true);
        pcChart.getDescription().setEnabled(false);
        pcChart.setExtraOffsets(5, 10, 5, 5);

        pcChart.setDragDecelerationFrictionCoef(0.95f);

//        tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

//        pcChart.setCenterTextTypeface(Typeface.createFromAsset(getAssets(), "OpenSans-Light.ttf"));
//        pcChart.setCenterText(generateCenterSpannableText());

        pcChart.setExtraOffsets(20.f, 0.f, 20.f, 0.f);

        pcChart.setDrawHoleEnabled(true);
        pcChart.setHoleColor(Color.WHITE);

        pcChart.setTransparentCircleColor(Color.WHITE);
        pcChart.setTransparentCircleAlpha(110);

        pcChart.setHoleRadius(58f);
        pcChart.setTransparentCircleRadius(61f);

        pcChart.setDrawCenterText(true);

        pcChart.setRotationAngle(0);
        // enable rotation of the chart by touch
        pcChart.setRotationEnabled(true);
        pcChart.setHighlightPerTapEnabled(true);

        // pcChart.setUnit(" €");
        // pcChart.setDrawUnitsInChart(true);

        // add a selection listener
        pcChart.setOnChartValueSelectedListener(this);

        setData2(4, 100);

        pcChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
        // pcChart.spin(2000, 0, 360);

        Legend l = pcChart.getLegend();
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
        l.setOrientation(Legend.LegendOrientation.VERTICAL);
        l.setDrawInside(false);
        l.setEnabled(false);

    }
}

interface initTongjiTu {

    void getNetData();//获取网络接口数据

    void setData0();//第一次配置的时候加入空数据，不然显示不出来

    //初始化条形统计图配置
    void initTongjituOption2();

    //显示条形统计图
    void initTongjitu();

    void setData(int count, float range);

    void initGridView();

    //为扇形图添加空数据
    void initShanXingTuNull();

    //为扇形统计图加空数据
    void setData2NULL();

    //初始化扇形统计图
    void initShanXingTu();

    //为扇形统计图加数据
    void setData2(int count, float range);


    void initGridView2();
}
